# -*- coding: utf-8 -*-
"""
Created on Wed Jun 10 13:53:40 2020

@author: Farman
"""

import numpy
import joblib

file_name = 'LandsatWRS2CornerPointsWRScornerPoints_0.csv'
dump_file = 'wrs_control_points.joblib'

with open(file_name) as f:
    lines = f.readlines()

lines = lines[1:]

lines = [line.rstrip() for line in lines if line.rstrip()!='']

path_row = []
control_lon_lat = []
up_left_lon_lat = []
up_rightt_lon_lat = []
bottom_left_lon_lat = []
bottom_right_lon_lat = []


for line in lines:
    cells = line.split(',')
    cells = [float(cell) for cell in cells]
    path_row.append([cells[0], cells[1]])
    control_lon_lat.append([cells[3], cells[2]])
    up_left_lon_lat.append([cells[5], cells[4]])
    up_rightt_lon_lat.append([cells[7], cells[6]])
    bottom_left_lon_lat.append([cells[9], cells[8]])
    bottom_right_lon_lat.append([cells[11], cells[10]])
    
path_row = numpy.array([[int(path), int(row)] for [path, row] in path_row])
control_lon_lat = numpy.array(control_lon_lat)
up_left_lon_lat = numpy.array(up_left_lon_lat)
up_rightt_lon_lat = numpy.array(up_rightt_lon_lat)
bottom_left_lon_lat = numpy.array(bottom_left_lon_lat)
bottom_right_lon_lat = numpy.array(bottom_right_lon_lat)

data = path_row, control_lon_lat, up_left_lon_lat, up_rightt_lon_lat, bottom_left_lon_lat, bottom_right_lon_lat
joblib.dump(data, dump_file)
